package LeetCode;

import java.util.Arrays;

public class LC_136_SingleNumber {
    public static void main(String[] args) {

    }

    static class Solution {
        public int singleNumber(int[] nums) {
            if (nums.length == 1) {
                return nums[0];
            } else if (nums.length % 2 == 0) {
                return 0;
            } else {
                Arrays.sort(nums);
                int n = nums.length - 1;
                for (int i = 0; i < n; i += 2)
                    if (nums[i] != nums[i + 1]) return nums[i];
                return nums[n];
            }
        }

    }
}
